package com.redis;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LoggingHandler;

import java.nio.charset.StandardCharsets;

/**
 * @author 罗俊华
 * @date 2021/8/27 - 1:41 下午
 */
public class RedisClient {


    public static void main(String[] args) {

        NioEventLoopGroup group = new NioEventLoopGroup(2);


        ChannelFuture channelFuture = new Bootstrap()
                .group(group)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel ch) throws Exception {
                        ch.pipeline()
                                .addLast(new LoggingHandler())
//                                .addLast(new StringEncoder())
                                .addLast(new RedisProtocolChannelOutBoundHandler());

                    }
                }).connect("localhost", 6379);

        channelFuture.addListener((ChannelFuture c) -> {

            Channel channel = c.channel();

            channel.writeAndFlush("del key  ");

//            group.shutdownGracefully();

        });

    }
}
